<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 2024/10/27
  Time: 19:35
  To change this template use File | Settings | File Templates.
--%>

<html>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>
<%request.setCharacterEncoding("utf-8");%>
<% String id=request.getParameter("stuid");%>
<% String stuBiryhday=request.getParameter("stubirthday");%>
<% String stuClass=request.getParameter("stuclass");%>
<head>
    <title>更改数据</title>
    <%!ResultSet rs;%>
    <%
        String dbName="studb";
        String userName="root";
        String userPwd="123456";

        String url = "jdbc:mysql://localhost:3306/" + dbName + "?serverTimezone=Asia/Shanghai&user=" + userName + "&password=" + userPwd;
        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection conn=DriverManager.getConnection(url);
        String sql = "update student set birthday=?,stuclass=?where number=?";
        PreparedStatement prepareStatement=conn.prepareStatement(sql);
        prepareStatement.setString(1,stuBiryhday);
        prepareStatement.setString(2,stuClass);
        prepareStatement.setString(3,id);
        int result= prepareStatement.executeUpdate();
        if (result>0)
            out.print("<script type='text/javascript'>alert('修改成功');</script>");
        else
            out.print("<script type='text/javascript'>alert('修改失败');</script>");
        sql="select * from student";
        rs=prepareStatement.executeQuery(sql);
    %>
</head>
<body>
<table border="1">
    <th colspan="4" style="font-size: x-large;alignment: center">学生信息表</th>
    <tr style="text-align: center">
        <td>学号</td>
        <td>姓名</td>
        <td>生日</td>
        <td>班级</td>
    </tr>
    <% while(rs.next()){ %>
    <tr style="text-align: center">
        <td><%=rs.getString(1)%></td>
        <td><%=rs.getString(2)%></td>
        <td><%=rs.getString("birthday")%></td>
        <td><%=rs.getString("stuclass")%></td>
    </tr>
    <%}%>
    <%
        rs.close();
        prepareStatement.close();
        conn.close();
    %>
</table>
</body>
</html>
